package com.cloudlinkscm.loms.services.base.notify.domain.email;

import com.cloudlinkscm.loms.services.base.notify.dao.EmailMessageDao;
import com.cloudlinkscm.loms.services.base.notify.domain.AbstractMessageManager;
import com.cloudlinkscm.loms.services.base.notify.domain.notifier.concrete.EmailNotifier;
import com.cloudlinkscm.loms.services.base.notify.model.entity.EmailMessage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : tac
 * @date : 2017/6/16
 */

@Component
public class EmailMessageManager extends AbstractMessageManager<EmailMessage> {
    private EmailMessageDao dao;

    @Autowired
    public EmailMessageManager(EmailMessageDao dao,
                               EmailNotifier defaultNotifier,
                               EmailMessageFlowManager messageFlowManager) {
        super(dao, defaultNotifier, messageFlowManager);
        this.dao = dao;
    }

    @Override
    public PageInfo<EmailMessage> listMessage4Send(int num) {
        PageHelper.startPage(1, num);
        return new PageInfo<>(dao.listMessage4Send());
    }

    @Override
    public boolean isSendNow(EmailMessage message) {
        return message.getSendDate() == null;
    }

    @Override
    public int setStatus(String id, Integer status) {
        EmailMessage message = new EmailMessage();
        message.setId(id);
        message.setStatus(status);
        return dao.updateByPrimaryKeySelective(message);
    }
}
